/**
  ******************************************************************************
  * @file   
  * @brief  
  ******************************************************************************
  * @note

 */
/* Includes ------------------------------------------------------------------*/
#include "Service_Communication.h"
/* Private variables ---------------------------------------------------------*/
uint8_t data_frame[8];
/* Global variables ---------------------------------------------------------*/
TaskHandle_t Can_Handle;
MI_Motor Motor1;
uint32_t Motor_Can_ID;
/* Definitions ---------------------------------------------------------*/
void Can_Service(void *arg);
/*Founctions------------------------------------------------------------------*/
void Service_Communication_Init(){
	canfd_filter(&hfdcan1);
	Init_Motor(&Motor1,0x7F,1,Current_mode);
	xTaskCreate(Can_Service,          /* Task function. */
              "Can_Service",     /* Task Name. */
              Normal_Stack_Size,   /* Stack depth. */
              NULL,                /* Task parameter */
              PriorityBelowNormal, /* Priority */
              &Can_Handle);      /* Task handle */
}

void Can_Service(void *arg)
{
    for (;;)
    {			
//				Enable_Motor(&Motor1);
					Set_Current(&Motor1,PID_Motor_Speed.output_value);
					vTaskDelay(1);  // Pass to next ready task
    }
}

/* Exported function declarations --------------------------------------------*/

void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
{
	HAL_FDCAN_GetRxMessage(&hfdcan1,FDCAN_RX_FIFO0,&RxHeader,data_frame);
	Motor_Can_ID=Get_Motor_ID(RxHeader.Identifier);
	switch(Motor_Can_ID)
	{
		case 0X7F:            
			Motor_Data_Handler(&Motor1,data_frame,RxHeader.Identifier);
			break;
		case 0X02:            

			break;
		case 0X03:            

			break;		
  }
}


